#include "stdafx.h"
#include "base/system/module_walker.h"

ModuleWalker::ModuleWalker()
{

}

ModuleWalker::~ModuleWalker()
{

}

MODULEENTRY32 * ModuleWalker::Get()
{
    return &m_oModuleEntry;
}

BOOL ModuleWalker::Start(DWORD nPid)
{
    m_hSnapshot.Set(::CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, nPid));
    if(INVALID_HANDLE_VALUE == m_hSnapshot) {
        return FALSE;
    }

    memset(&m_oModuleEntry, 0, sizeof(MODULEENTRY32));
    m_oModuleEntry.dwSize = sizeof(MODULEENTRY32);
    return ::Module32First(m_hSnapshot, &m_oModuleEntry);
}

BOOL ModuleWalker::Next()
{
    return ::Module32Next(m_hSnapshot, &m_oModuleEntry);
}